package com.g8.pethospitallearnbackend.service.impls;

import com.g8.pethospitallearnbackend.entity.Disease;
import com.g8.pethospitallearnbackend.exception.CustomException;
import com.g8.pethospitallearnbackend.mapper.DiseaseMapper;
import com.g8.pethospitallearnbackend.mapper.TypeMapper;
import com.g8.pethospitallearnbackend.service.DiseaseService;
import com.g8.pethospitallearnbackend.utils.responseUtil.ResponseStatusEnum;
import org.apache.coyote.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DiseaseImpl implements DiseaseService {
    @Autowired
    private DiseaseMapper diseaseMapper;
    @Autowired
    private TypeMapper typeMapper;
    @Override
    public List<Disease> getDiseasesByTypeId(String typeId) {
        return diseaseMapper.selectDiseasesByTypeId(typeId);
    }

    @Override
    public String getDiseaseIdByName(String diseaseName) {
        return diseaseMapper.selectDiseaseIdByName(diseaseName);
    }

    @Override
    public Disease getADiseaseById(String diseaseId) {
        Disease disease=diseaseMapper.selectADiseaseById(diseaseId);
        if(disease==null) throw new CustomException(ResponseStatusEnum.DATA_NOT_EXIST,"不存在该"+diseaseId);
        //把typeId换成typeName
        String typeName=typeMapper.selectTypeNameById(disease.getTypeId());
        disease.setTypeId(typeName);

        return disease;
    }

    @Override
    public List<Disease> getAllIdAndName() {
        List<Disease> allIdAndName=diseaseMapper.selectAllIdAndName();
        if(allIdAndName==null||allIdAndName.isEmpty()) throw new CustomException(ResponseStatusEnum.BAD_REQUEST,"无结果");
        return allIdAndName;
    }
}
